function produceIndex(type) {
	var authorName = $("#authorName").val();
	var authorName2 = $("#authorName2").val();
	if (authorName == "") {
		alert("作者姓不能为空")
		return;
	}
	var year = $("#year").val();
	if (year == "") {
		alert("年份不能为空")
		return;
	}

	// var name = chineseToPinYin(authorName);
	//$('#tip').modal();

	$.confirm({
		title: "确认！",
		content: "索引号是参考文献的唯一标识，是由第一作者和文献年份共同决定的，一旦生成索引号，将不得进行修改，如果发现索引号有误，必须重新生成参考文献，确定生成？",
		buttons: {
			ok: {
				text: '确认',
				btnClass: 'btn-primary',
				action: function () {

					var data1 = "";
					$.ajax({
						type: "Post",
						dataType: 'json',
						async: true,
						data: {
							'language': type,
							'firstName': authorName2,
							'lastName': authorName,
							'year': year,
							'startCode': "J"
						},
						url: '/ma/userIndexNo/generateUserIndexNo',
						success: function (data) {
							$("#indexNo").val(data)
							$("#produceIndex").attr("disabled", true);

						}
					});
				},
				cancel: {
					text: '取消',
					btnClass: 'btn-primary',
					action: function () {
						// button action.
					}
				}
			}
		}
	})
}
function generateItem(type){
	var tableInfo="";
	var tableObj = document.getElementById("authorTable");
	if(tableObj.rows.length==0){
		alert("请添加作者列表！")
		return;
	}
	for (var i = 0; i < tableObj.rows.length; i++) {    // 遍历Table的所有Row
		for (var j = 1; j < tableObj.rows[i].cells.length; j++) {   // 遍历Row中的每一列
			tableInfo += tableObj.rows[i].cells[j].innerText;   // 获取Table中单元格的内容
			tableInfo += ",";
		}
		tableInfo += ";";
	}
	var title="";
	if(type==1){
		title=$('#title').val();
	}else{
		title=$('#title2').val();
	}
	$.ajax({
		type: "Post",
		dataType: 'json',
		data:{
			'type':type,
			'title': title,
			'journalName': $('#journalSelect option:selected') .val(),
			'year': $('#year').val(),
			'volume': $('#volume').val(),
			'num': $('#num').val(),
			'startPage': $('#startPage').val(),
			'endPage': $('#endPage').val(),
			'tableInfo':tableInfo
		},
		url: '/ma/journal/generateItem',
		success: function(data) {
			console.log(data)
			$("#item").val(data)
			$("#item").height = 'auto';
			var textarea = document.getElementsByTagName('textarea')[0];
			textarea.setAttribute('style','height:'+(textarea.scrollHeight)+'px');
			textarea.setAttribute('style','width:'+(400)+'px');
			/*
			 * $("#item").height = (textarea.scrollHeight) + 'px';
			 * $("#item").width =400 + 'px';
			 */
		}
	});
}
function generateItem2(type){
	var tableInfo="";
	var tableObj = document.getElementById("authorTable1");
	for (var i = 0; i < tableObj.rows.length; i++) {    // 遍历Table的所有Row
		for (var j = 1; j < tableObj.rows[i].cells.length; j++) {   // 遍历Row中的每一列
			tableInfo += tableObj.rows[i].cells[j].innerText;   // 获取Table中单元格的内容
			tableInfo += ",";
		}
		tableInfo += ";";
	}
	var title="";
	if(type==1){
		title=$('#ctitle').val();
	}else{
		title=$('#ctitle2').val();
	}
	$.ajax({
		type: "Post",
		dataType: 'json',
		data:{
			'type':type,
			'title': title,
			'journalName': $('#journalSelect1 option:selected').val(),
			'year': $('#year1').val(),
			'volume': $('#volume1').val(),
			'num': $('#num1').val(),
			'startPage': $('#startPage1').val(),
			'endPage': $('#endPage1').val(),
			'tableInfo':tableInfo
		},
		url: '/ma/journal/generateItem',
		success: function(data) {
			console.log(data)
			$("#item1").val(data)
			$("#item1").height = 'auto';
			var textarea = document.getElementsByTagName('textarea')[0];
			textarea.setAttribute('style','height:'+(textarea.scrollHeight)+'px');
			textarea.setAttribute('style','width:'+(400)+'px');
			document.getElementById("regenerateItem").disabled=true
		}
	});
	var tableInfo="";
}
function queryJournal(type){
	$("#journalSelect").empty()
	$("#journalIndex").val("")
	$("#authorName").val("")
	$("#authorName2").val("")
	$("#authorNameMiddle").val("")
	$("#authorEmail").val("")
	$("#year").val("")
	$("#indexNo").val("")
	$("#diskPath").val("")
	$("#volume").val("")
	$("#num").val("")
	$("#startPage").val("")
	$("#endPage").val("")
	$("#title").val("")
	$("#title1").val("")
	$("#title2").val("")
	$("#position").val("")
	$("#firstKeyword").val("")
	$("#secondKeyword").val("")
	$("#thirdKeyword").val("")
	$("#forthKeyword").val("")
	$("#item").val("")
	$("#note").val("")
	$("#authorTable").empty()
	getJournal(type)
	document.getElementById("emailErr8").innerHTML = "";
	$('#add').modal();
}
function getJournal(type){
	$("#journalSelect").empty()
	$("#journalSelect1").empty()
	$.ajax({
		type: "Post",
		contentType:'application/x-www-form-urlencoded; charset=UTF-8',
		dataType: 'json',
		data:{
			'type':type
		},
		url: '/ma/journal/queryJournal',
		success: function(data) {
			$("#journalSelect").append("<option id='-1' value='请选择'>请选择</option>");
			$("#journalSelect1").append("<option id='-1' value='请选择'>请选择</option>");
			if(type ==1){
				for( let i of data){
					$("#journalSelect").append('<option id="'+i.indexNo+'" value="'+i.journalName+'">'+i.journalName+'</option>');
					$("#journalSelect1").append('<option id="'+i.indexNo+'" value="'+i.journalName+'">'+i.journalName+'</option>');
				}
			}else {
				for( let i of data){
					$("#journalSelect").append('<option id="'+i.indexNo+'" value="'+i.journalName2+'">'+i.journalName2+'</option>');
					$("#journalSelect1").append('<option id="'+i.indexNo+'" value="'+i.journalName2+'">'+i.journalName2+'</option>');
				}
			}
			if(type==1){
				$("#journalSelect").append("<option id='addnewjournal1' value='addnewjournal1'>addnew</option>");
			}else{
				$("#journalSelect").append("<option id='addnewjournal' value='addnewjournal'>addnew</option>");
			}
			$("#journalSelect1").append("<option id='addnewjournal' value='addnewjournal'>addnew</option>");
			// $("#journalIndex").val(data[0].indexNo)

		}
	})
}
$("#journalSelect").change(function(){
	if($("#journalSelect option:checked").val()=="addnewjournal"||$("#journalSelect option:checked").val()=="addnewjournal1"){
		console.log("addnew")
		// $("#add").load("/ma/miuser/journalAdd.html");
		var data =judgeUserAuthority()
		if(data=="superUser"||data=="highUser"){
			if($("#journalSelect option:checked").val()=="addnewjournal"){
				window.location.href='/ma/miuser/journalAdd.html';
			}else {
				window.location.href='/ma/miuser/journalAdd1.html';
			}

		}else if(data=="middleUser"||data=="primaryUser"){
			$.confirm({
				title: "提示!",
				content: "您没有该权限",
				confirm: function () {

				}
			});
		}
		$("#journalIndex").val("")
	}else{
		$("#journalIndex").val($("#journalSelect option:checked").attr("id"))
	}
})
$("#journalSelect1").change(function(){
	if($("#journalSelect1 option:checked").val()=="addnewjournal"){
		console.log("addnew")
		// $("#add").load("/ma/miuser/journalAdd.html");
		var data =judgeUserAuthority()
		if(data=="superUser"||data=="highUser"){
			window.location.href='/ma/miuser/journalAdd.html';
		}else if(data=="middleUser"||data=="primaryUser"){
			$.confirm({
				title: "提示!",
				content: "您没有该权限",
				confirm: function () {

				}
			});
		}
		$("#journalIndex1").val("")
	}else{
		$("#journalIndex1").val($("#journalSelect1 option:checked").attr("id"))
	}
})
function judgeUserAuthority() {
	var data1;
	$.ajax({
		type: "post",
		url: "/ma/queryAuth",
		async : false,
		contentType: 'application/json;charset=utf-8',
		success: function (data) {
			data1 = data;
		}
	})
	return data1;
}

var tableInfo1="";

function addToAuthorList(type) {
	var authorNameMiddle="";
	var authorName=""
	if(type==1){
		var authorNameMiddle=$("#authorNameMiddle").val();
		authorName =$("#authorName").val()+" "+authorNameMiddle+" "+$("#authorName2").val();
	}else {
		authorName =$("#authorName").val()+$("#authorName2").val();
	}

	if(authorName==""){
		alert("作者姓名不能为空");
		return;
	}
	if($("#indexNo").val()==""){
		alert("请先生成索引号！");
		return;
	}else {
		/* var authorName2=$("#authorName2").val(); */
		var authorEmail = $("#authorEmail").val();
		if(authorEmail.length<=0){
			authorEmail = " "
		}

		tableInfo1 += $("#authorName").val() + "," + authorNameMiddle + "," + $("#authorName2").val() + "," + authorEmail;

		tableInfo1 += ";";

		var bo = false;
		if (authorEmail != null && authorEmail.length > 0) {
			bo = checkuseremail()
		}
		if (bo || authorEmail.length==1) {
			var length = document.getElementById("authorTable").rows.length + 1
			var id1 = authorName + length;
			var id2 = authorEmail + length;
			$("#authorTable").append("<tr><td>" + length + "</td><td id=" + id1 + ">" + authorName + "</td><td id=" + id2 + ">" + authorEmail + "</td>");
			$("#authorName").val("");
			$("#authorName2").val("");
			$("#authorEmail").val("");
			if (type == 1) {
				$("#authorNameMiddle").val("");
			}
		}
	}
}

function submit(type) {
	// var tableInfo="";
	var tableObj = document.getElementById("authorTable");
	if(tableObj.rows.length==0){
		alert("请添加作者列表！")
		return;
	}
	// for (var i = 0; i < tableObj.rows.length; i++) {    // 遍历Table的所有Row
	// 	for (var j = 1; j < tableObj.rows[i].cells.length; j++) {   // 遍历Row中的每一列
	// 		tableInfo += tableObj.rows[i].cells[j].innerText;   // 获取Table中单元格的内容
	// 		tableInfo += ",";
	// 	}
	// 	tableInfo += ";";
	// }
	if(type==2){
		var indexNo=$("#indexNo").val();
		$.ajax({
			type: "Post",
			data:JSON.stringify({
				"indexNo":indexNo,
				'title2': $('#title2').val(),
				'title1': $('#title1').val(),
				'journalIndexNo': $('#journalIndex').val(),
				'year': $('#year').val(),
				'volume': $('#volume').val(),
				'num': $('#num').val(),
				'startPage': $('#startPage').val(),
				'endPage': $('#endPage').val(),
				'diskPath': $('#diskPath').val(),
				'position': $('#position').val(),
				'firstKeyword': $('#firstKeyword').val(),
				'secondKeyword': $('#secondKeyword').val(),
				'thirdKeyword': $('#thirdKeyword').val(),
				'forthKeyword': $('#forthKeyword').val(),
				'note': $('#note').val(),
				'item': $('#item').val(),
				'type':2,
				'tableInfo':tableInfo1
			}),
			contentType: "application/json;charset=utf-8",
			dataType: 'json',
			url: '/ma/journal/addJournalPaper',
			success: function(data) {
				tableInfo1=""
				console.log(data)
				var item =data.split("+")[0];
				var date =data.split("+")[1];
				var status =data.split("+")[2];
				$('#sample-table-2').bootstrapTable('insertRow', {
					index:$('#sample-table-2').bootstrapTable('getOptions').totalRows,
					row:{
						indexNo:indexNo,
						title2:$('#title2').val(),
						'userIndexNoTable.item':item,
						'userIndexNoTable.stamp':date,
						'userIndexNoTable.status':status
					}

				});
			}
		});
	}else{
		var indexNo=$("#indexNo").val();
		$.ajax({
			type: "Post",
			data:JSON.stringify({
				"indexNo":indexNo,
				'title': $('#title').val(),
				'journalIndexNo': $('#journalIndex').val(),
				'year': $('#year').val(),
				'volume': $('#volume').val(),
				'num': $('#num').val(),
				'startPage': $('#startPage').val(),
				'endPage': $('#endPage').val(),
				'diskPath': $('#diskPath').val(),
				'position': $('#position').val(),
				'firstKeyword': $('#firstKeyword').val(),
				'secondKeyword': $('#secondKeyword').val(),
				'thirdKeyword': $('#thirdKeyword').val(),
				'forthKeyword': $('#forthKeyword').val(),
				'note': $('#note').val(),
				'item': $('#item').val(),
				'type':1,
				'tableInfo':tableInfo1
			}),
			contentType: "application/json",
			dataType: 'json',
			url: '/ma/journal/addJournalPaper',
			success: function(data) {
				tableInfo1=""
				console.log(data)
				var item =data.split("+")[0];
				var date =data.split("+")[1];
				var status =data.split("+")[2];
				$('#sample-table-2').bootstrapTable('insertRow', {
					index:$('#sample-table-2').bootstrapTable('getOptions').totalRows,
					row:{
						indexNo:indexNo,
						title:$('#title').val(),
						'userIndexNoTable.item':item,
						'userIndexNoTable.stamp':date,
						'userIndexNoTable.status':status
					}

				});


			}
		});
	}


}
function checkuseremail() {
	var str = document.getElementById('authorEmail').value;
	// 在JavaScript中，正则表达式只能使用"/"开头和结束，不能使用双引号
	//var reg = /^([a-z|A-Z|0-9|_])+@([a-z|A-Z|0-9|_])+\.com|edu|cn|net$/;
	var reg = /^(?:\w+\.?)*\w+@(?:\w+\.)*\w+$/;
	if (reg.test(str)) {
		check8 = 1;
		document.getElementById("emailErr8").innerHTML = "<i class='glyphicon glyphicon-ok' style='color:green'></i>";
		return true;
	} else {
		document.getElementById("emailErr8").innerHTML = "<i class='glyphicon glyphicon-remove'></i>";
		return false;
	}
}

var exporttype = ""
$('#exporttype').change(function () {
	exporttype= $(this).val()
});

function exportData(){
	// if(exporttype=="selected"){
	// 	if($('#sample-table-2').bootstrapTable("getSelections")==""){
	// 		alert("请选择文献")
	// 	}else{
	// 		$('#sample-table-2').tableExport({
	// 			type:'excel',
	// 			exportDataTe: exporttype,
	// 			Icons:'glyphicon glyphicon-export',
	// 			ignoreColumn: [0],//忽略某一列的索引
	// 			fileName: 'Chinesejournals',//下载文件名称
	//
	// 			//data:$("#sample-table-2").bootstrapTable("getSelections"),
	// 			// onCellHtmlData: function (cell, row, col, data){//处理导出内容,自定义某一行、某一列、某个单元格的内容
	// 			// 	console.log(data)
	// 			// 	return data;
	// 			// },
	// 		});
	// 	}
	//
	// }else {
		$('#sample-table-2').tableExport({
			type:'excel',
			exportDataTe: exporttype,
			Icons:'glyphicon glyphicon-export',
			//ignoreColumn: [0],//忽略某一列的索引
			fileName: 'Chinesejournals',//下载文件名称
			//data:$("#sample-table-2").bootstrapTable("getSelections"),
			// onCellHtmlData: function (cell, row, col, data){//处理导出内容,自定义某一行、某一列、某个单元格的内容
			// 	console.log(data)
			// 	return data;
			// },
		});
	//}

}